#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int ret = 0, zero = k;
        for (int begin = 0, end = 0; end < nums.size(); end++)
        {
            if (!nums[end]) zero--;
            if (zero < 0)
            {
                while (nums[begin++]);
                zero++;
            }
            ret = max(ret, end - begin + 1);
        }
        return ret;
    }
};